package com.spbl.apache.shiro.config.interceptor;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.util.ArrayList;
import java.util.List;

/**
 * Description(配置拦截器)
 * author: Gao xueyong
 * Create at: 2020/5/30 4:16 下午
 */
@Configuration
public class IntercepterConfig implements WebMvcConfigurer {

    @Autowired
    private VerfyInterceptor verfyInterceptor;

    //构造方法
    public IntercepterConfig(VerfyInterceptor verfyInterceptor) {
        this.verfyInterceptor = verfyInterceptor;
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
//        //白名单
//        List<String> excludePath = new ArrayList<>();
////        excludePath.add("/user_register"); //注册
//        excludePath.add("/login"); //登录
//        excludePath.add("/logout"); //登出
////        excludePath.add("/static/**");  //静态资源
////        excludePath.add("/assets/**");  //静态资源

//        registry.addInterceptor(verfyInterceptor)
//                .addPathPatterns("/**")
//                .excludePathPatterns(excludePath);
        List<String> excludePath = new ArrayList<>();
//        excludePath.add("/user_register"); //注册
        excludePath.add("/login.html"); //登录
        excludePath.add("/login"); //登录
        excludePath.add("/logout"); //登出
        registry.addInterceptor(verfyInterceptor).excludePathPatterns(excludePath);
        WebMvcConfigurer.super.addInterceptors(registry);

    }
}
